package be.myandroid.games.menu;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import be.myandroid.games.StateManager.State;
import be.myandroid.games.StateManager.stateListener;
import be.myandroid.games.spritetext.LabelMaker;
import be.myandroid.games.spritetext.Projector;

public class ProxyMenu extends AbstractMenu implements stateListener{

	private PauseMenu pauseMenu;
	private WonMenu wonMenu;
	private FailMenu failMenu;
	
	public ProxyMenu(Context context){
		pauseMenu = new PauseMenu(context);
		wonMenu = new WonMenu();
		failMenu = new FailMenu();
		
		state.addListener(this);
	}
	
	@Override
	public void initialize(GL10 gl, Drawable background, LabelMaker parent,
			Paint paint) {
		pauseMenu.initialize(gl, background, parent, paint);
		wonMenu.initialize(gl, background, parent, paint);
		failMenu.initialize(gl, background, parent, paint);
	}

	@Override
	protected void layoutItems(float mWidth, float mHeight) {
		pauseMenu.layoutItems(mWidth, mHeight);
		wonMenu.layoutItems(mWidth, mHeight);
		failMenu.layoutItems(mWidth, mHeight);
	}

	@Override
	public void draw(GL10 gl, LabelMaker mLabels, Projector mProjector) {
		switch(state.getState()){
		case PAUSE:
		case MENU:
			pauseMenu.draw(gl, mLabels, mProjector);
			break;
		case FAILED:
			failMenu.draw(gl, mLabels, mProjector);
			break;
		case WON:
			wonMenu.draw(gl, mLabels, mProjector);
			break;
		}
	}

	@Override
	public void isChanged(State newState) {
		parent.notifyChange();
	}

}
